#include "SimpleNetGameModeBase.h"
#include "TCP/FTcpExample.h"
#include "UDP/FUdpExample.h"
#include "Http/FHttpExample.h"

ASimpleNetGameModeBase::ASimpleNetGameModeBase()
{
	TcpExample = nullptr;
	UdpExample = MakeShareable(new FUdpExample);
}

void ASimpleNetGameModeBase::SendHttpRequest()
{
	FHttpExample::SendGetRequest(TEXT("http://www.baidu.com"));
}


void ASimpleNetGameModeBase::ConnectSocket()
{
	if (!TcpExample)
	{
		TcpExample = MakeShareable(new FTcpExample);
		if (TcpExample->Connect("127.0.0.1", 7788))
			TcpExample->StartListen();
	}
}

void ASimpleNetGameModeBase::DisconnectSocket()
{
	if (TcpExample)
	{
		TcpExample->Close();
		TcpExample = nullptr;
	}
}

void ASimpleNetGameModeBase::SendSocketMsg(const FString& Msg) const
{
	if (TcpExample)
		TcpExample->SendMsg(Msg);
}


void ASimpleNetGameModeBase::SendUdpMsg(const FString& Msg) const
{
	UdpExample->SendMsg(Msg);
}
